<?php

namespace app\common\dao\system;

use app\common\model\system\SystemCity as model;
use app\common\dao\BaseDao;

class SystemCityDao extends BaseDao
{
    /**
    * 设置模型
    * @return model
    */
    protected function getModel(): string
    {
        return model::class;
    }


    public function getAll(array $where)
    {
        return ($this->getModel()::getDB())->where($where)
            ->order('city_id ASC')->field('city_id,name,merger_name,parent_id,level')->select();
    }

    public function getColumn(array $where)
    {
        return ($this->getModel()::getDB())->where($where)
            ->order('city_id ASC')->column('name,parent_id', 'city_id');
    }

    public function getCompleteAddress($cityId,$str = '',&$address = '')
    {
        $city = $this->getModel()::getDB()->where('city_id',$cityId)->find();
        $address = ($city->name??""). $str .$address;
        if($city && $this->getModel()::getDB()->where('city_id',$city->parent_id)){
            $this->getCompleteAddress($city->parent_id,$str,$address);
        }
        return trim($address,$str);
    }

}